/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Command;

import java.util.LinkedList;

/**
 *
 * @author Andreea
 */
public class CommandManager {
    private int maxUndos=100;
    private LinkedList history=new LinkedList();
    private LinkedList redoList=new LinkedList();
    public void invokeCommand(AbstractCommand command){
        if (command instanceof UndoCommand){
            undo();
            return;
        }
        if (command instanceof RedoCommand){
            redo();
            return;
        }
        if (command.doCommand()){
            addToHistory(command);
        }
    }
    private void undo(){
        if (history.size()>0){
            AbstractCommand undoCommand;
            undoCommand=(AbstractCommand)history.removeFirst();
            undoCommand.undo();
            redoList.addFirst(undoCommand);
        }
    }
}
